define(function (require) {
    var app = require('/../js/app');

    var datepicker = require('datepicker');
    var toastr=require('toastr');
    app.controller('excel_teamCtrl', ['$scope','$http','$filter',function ($scope, $http,$filter){


        datepicker($scope);

        $scope.condition={};

        $scope.orderParams={};

        var D={};
        $scope.getList = function (D) {
            var a= 0,b= 0,c= 0,d=0;
            $http({
                method: 'POST',
                url: "/admin/report/listTeamResult",
                data:D
            }).success(function(data) {
                console.log(data)
                $scope.orderParams=data;
                for(var i=0;i<data.length;i++){
                      a+= data[i].monthlyAmount;
                    b+=data[i].monthlyAnnualAmount;
                    c+=data[i].monthlyAvgAmount;
                    d+=data[i].quarterAnnualAmount;
                }
                $scope.monthlyAmountAll = a;
                $scope.monthlyAnnualAmountAll =b;
                $scope.monthlyAvgAmountAll =c;
                $scope.quarterAnnualAmountAll = d
            }).error(function() {
            });
        };

        var oDate=new Date();
        var oYear=oDate.getFullYear();
        var oMonth=oDate.getMonth()+1;
        var date=oYear+'-'+oMonth;
        $scope.date=date;
        $scope.getList({queryDate:date});

        //搜索
        $scope.search = function() {

            var param={};
            $scope.condition.queryDate=$scope.condition.queryDateX;
            $scope.condition.queryDate=$filter('date')($scope.condition.queryDate,'yyyy-MM');
            param=$scope.condition;
            $scope.getList(param);
            console.log(param)
        };

        //搜索重置
        $scope.reset=function(){
            $scope.condition = {};
            $scope.search();

        };

        //导出
        $scope.download=function(){
            var params={};
            params=$scope.condition;
            $http.post("/admin/report/excelTeamResult",params)
                .success(function (data){
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){
                });
        };

    }]);


});